class Solution
{
public:
    vector<int> getSumAbsoluteDifferences(vector<int> &nums)
    {
        int n = nums.size();
        vector<int> prefixSum(n + 1);
        partial_sum(nums.begin(), nums.end(), prefixSum.begin() + 1);
        vector<int> result(n);
        for (int i = 0; i < n; ++i)
        {
            result[i] = i * nums[i] - prefixSum[i] + prefixSum[n] - prefixSum[i + 1] - (n - i - 1) * nums[i];
        }
        return result;
    }
};